<?php
require_once 'common.php';

// Retrieve array of friends who've already added the app.
$user=$fb_user_id;
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.') AND has_added_app = 1';
$_friends = $facebook->api_client->fql_query($fql);

// Extract the user ID's returned in the FQL request into a new array.
$friends = array();
if (is_array($_friends) && count($_friends)) {
	foreach ($_friends as $friend) {
		$friends[] = $friend['uid'];
	}
}

// Convert the array of friends into a comma-delimeted string.
$friends = implode(',', $friends);

// Prepare the invitation text that all invited users will receive.
$content = <<<FBML
<fb:name uid="{$user}" firstnameonly="true" shownetwork="false"/> wants to invite you to Bundundu!
<fb:req-choice url="{$facebook->get_add_url()}" label="Add Bundundu calendar aplication to your profile!"/>
FBML;
?>

<fb:request-form action="http://apps.facebook.com/bundundu/" method="POST" invite="true" type="Bundundu App" content="<?php echo htmlentities($content);?>">
	<fb:multi-friend-selector max="20" actiontext="Here are your friends who haven't added Bundundu to their profile." showborder="true" rows="5" exclude_ids="<?php echo $friends;?>"></fb:request-form>


